package com.aloda.orangebank.service.impl;

import com.aloda.orangebank.mapper.CardMapper;
import com.aloda.orangebank.pojo.CardApplication;
import com.aloda.orangebank.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class CardServiceImpl implements CardService {

    @Autowired
    private CardMapper cardMapper;

    @Override
    public int cardLog(CardApplication cardApplication) {
        if (cardMapper.getLogNumByUn(cardApplication.getUsername())>4){
            return 2;
        }else if(cardMapper.getUserCardNumByUn(cardApplication.getUsername())<4){
            cardApplication.setApplyTime(LocalDateTime.now());
            cardMapper.addCardLog(cardApplication);
            return 1;
        }
        return 0;
    }
}
